﻿@model CoffeeShop.Models.Entities.User

@{
    Layout = null;
    var isDupUserName = (bool)ViewBag.IsDuplicateUserName;
}

<!DOCTYPE html>

<html>
<head>
    <link href="~/assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="~/assets/css/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="~/assets/css/font-awesome.min.css" rel="stylesheet">

    <link href="~/assets/css/jquery.gritter.css" rel="stylesheet" />
    <link href="~/assets/css/datepicker.css" rel="stylesheet" />
    <link rel="stylesheet" href="~/assets/css/ace.min.css">
    <link rel="stylesheet" href="~/assets/css/ace-responsive.min.css">
    <link rel="stylesheet" href="~/assets/css/ace-skins.min.css">

    <script src="~/assets/js/jquery-2.0.3.min.js"></script>
    <script src="~/assets/js/bootstrap.min.js"></script>
    <script src="~/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="~/assets/js/bootbox.min.js"></script>
    <script src="~/assets/js/jquery.gritter.min.js"></script>
    <script src="~/assets/js/spin.min.js"></script>
    <script src="~/assets/js/bootstrap-datepicker.min.js"></script>
    <script src="~/assets/js/jquery.maskedinput.min.js"></script>
    <script src="~/assets/js/ace-elements.min.js"></script>
    <script src="~/assets/js/ace.min.js"></script>
    <script src="~/assets/js/jquery.validate.min.js"></script>

    <meta name="viewport" content="width=device-width" />
    <title>Đăng ký thành viên</title>
</head>

<body class="login-layout">
    <div class="main-container container-fluid">
        <div class="main-content">
            <div class="row-fluid">
                <div class="span12">
                    <div class="login-container">
                        <div class="row-fluid">
                            <div class="center">
                                <h1>
                                    <i class="icon-leaf green"></i>
                                    <span class="red">Ace</span>
                                    <span class="white">Application</span>
                                </h1>
                                <h4 class="blue">&copy; Company Name</h4>
                            </div>
                        </div>

                        <div class="space-6"></div>

                        <div class="row-fluid">
                            <div class="position-relative">
                                <form action="/User/Register" method="post" name="RegisterForm" id="registerForm">
                                    @Html.AntiForgeryToken();

                                    <!--/Register Form-->
                                    <div id="signup-box" class="signup-box visible widget-box no-border">
                                        <div class="widget-body">
                                            <div class="widget-main">
                                                <h4 class="header green lighter bigger">
                                                    <i class="icon-group blue"></i>
                                                    Đăng ký thành viên
                                                </h4>

                                                <div class="space-6"></div>

                                                <fieldset>
                                                    @if (isDupUserName)
                                                    {
                                                        <div class="control-group error" id="groupUserName">
                                                            <div class="controls">
                                                                <label>
                                                                    <span class="block input-icon input-icon-right">
                                                                        @Html.TextBoxFor(userName => Model.UserName, null, new { @type = "text", @class = "span12", @placeholder = "Tên tài khoản", @id = "txtUserName", @onfocus = "this.oldvalue = this.value;", @onchange = "onChangeTest(this);this.oldvalue = this.value;" })
                                                                        <div id="duplicateUserName" class="help-block">Tên đăng nhập đã được sử dụng!</div>
                                                                        <i class="icon-user"></i>
                                                                    </span>
                                                                </label>
                                                            </div>
                                                        </div>
                                                    }
                                                    else
                                                    {
                                                        <div class="control-group" id="groupUserName">
                                                            <div class="controls">
                                                                <label>
                                                                    <span class="block input-icon input-icon-right">
                                                                        @Html.TextBoxFor(userName => Model.UserName, null, new { @type = "text", @class = "span12", @placeholder = "Tên tài khoản", @id = "txtUserName", @onfocus = "this.oldvalue = this.value;", @onchange = "onChangeTest(this);this.oldvalue = this.value;" })
                                                                        <i class="icon-user"></i>
                                                                    </span>
                                                                </label>
                                                            </div>
                                                        </div>
                                                    }

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <span class="block input-icon input-icon-right">
                                                                    @Html.TextBoxFor(userName => Model.Password, new { @type = "password", @class = "span12", @placeholder = "Mật khẩu" })
                                                                    <i class="icon-lock"></i>
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <span class="block input-icon input-icon-right">
                                                                    <input id="repeatPassword" name="repeatPassword" type="password" class="span12" placeholder="Xác nhận mật khẩu" />
                                                                    <i class="icon-retweet"></i>
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <span class="block input-icon input-icon-right">
                                                                     @*@Html.TextBoxFor(dateOfBirth => Model.DateOfBirth, null, new { @type = "text", @class = "span12 ", @placeholder = "Ngày sinh" })*@
                                                                    <input class="span12 date-picker" type="text" name="DateOfBirth" placeholder="Ngày sinh" />
                                                                    <i class="icon-calendar"></i>
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group" id="fullNameGroup">
                                                        <div class="controls">
                                                            <label>
                                                                <span class="block input-icon input-icon-right">
                                                                    @Html.TextBoxFor(fullName => Model.FullName, null, new { @type = "text", @class = "span12", @placeholder = "Tên đầy đủ" })
                                                                    <i class="icon-user"></i>
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <span class="block input-icon input-icon-right">
                                                                    @Html.TextBoxFor(address => Model.Address, new { @type = "text", @class = "span12", @maxlength = "250", @placeholder = "Địa chỉ" })
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <select id="gender" name="Gender" class="span12">
                                                                    <option value="" />
                                                                    <option value="Nam" />
                                                                    Nam
															            <option value="Nữ" />
                                                                    Nữ
                                                                </select>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <span class="block input-icon input-icon-right">
                                                                    @Html.TextBoxFor(phoneNumber => Model.PhoneNumber, null, new { @type = "text", @class = "span12 input-medium input-mask-phone", @placeholder = "Số điện thoại" })
                                                                    <i class="icon-phone"></i>
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <span class="block input-icon input-icon-right">
                                                                    @Html.TextBoxFor(email => Model.Email, null, new { @type = "email", @class = "span12", @placeholder = "Email" })
                                                                    <i class="icon-envelope-alt"></i>
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <div class="controls">
                                                            <label>
                                                                <input type="checkbox" />
                                                                <span class="lbl">I accept the
																<a href="#">User Agreement</a>
                                                                </span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="space-24"></div>

                                                    <div class="clearfix">
                                                        <button type="reset" class="width-30 pull-left btn btn-small">
                                                            <i class="icon-refresh"></i>
                                                            Xóa
                                                        </button>

                                                        <button type="submit" class="width-65 pull-right btn btn-small btn-success">
                                                            Đăng ký
															<i class="icon-arrow-right icon-on-right"></i>
                                                        </button>
                                                    </div>
                                                </fieldset>
                                            </div>

                                            <div class="toolbar center">
                                                <a href="/User/Login" class="back-to-login-link">
                                                    <i class="icon-arrow-left"></i>
                                                    Trở về màn hình đăng nhập
                                                </a>
                                            </div>
                                        </div>
                                        <!--/widget-body-->
                                    </div>
                                    <!--/Register-box-->
                                </form>
                                <!--/Register Form-->
                            </div>
                        </div>
                        <!--/widget-body-->
                    </div>
                    <!--/signup-box-->
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    $(document).ready(function () {
        //Variable to check change value of UserName
        var newUserNameValue = "";
        var oldUserNameValue = "";

        //$('#UserName').val('');
        //$('#Password').val('');

        $('.date-picker').datepicker({ autoclose: true }).next().on(ace.click_event, function () {
            $(this).prev().focus();
        });

        $.mask.definitions['~'] = '[+-]';
        $('.input-mask-phone').mask('(84) 9999-999-999');

        $("#registerForm").validate({
            errorElement: 'div',
            errorClass: 'help-block',
            focusInvalid: true,
            rules: {
                UserName: {
                    required: true,
                    maxlength: 50
                },
                Password: {
                    required: true,
                    minlength: 6,
                    maxlength: 50
                },
                repeatPassword: {
                    required: true,
                    maxlength: 50,
                    equalTo: "#Password"
                },
                DateOfBirth: {
                    required: true,
                    date: true
                },
                Gender: {
                    required: true
                },
                FullName: {
                    required: false
                },
                Address: {
                    required: true,
                    maxlength: 250
                },
                PhoneNumber: {
                    required: true
                },
                Email: {
                    required: true,
                    email: true
                }
            },
            messages: {
                UserName: {
                    required: "Xin hãy tên tài khoản đăng nhập!",
                    maxlength: "Tên đăng nhập tối đa 50 ký tự!"
                },
                Password: {
                    required: "Xin hãy nhập mật khẩu đăng nhập!",
                    minlength: "Xin hãy nhập ít nhất 6 ký tự!",
                    maxlength: "Tên đăng nhập tối đa 50 ký tự!"
                },
                repeatPassword: {
                    required: "Xin hãy nhập xác nhận mật khẩu đăng nhập!",
                    equalTo: "Xác nhận mật khẩu không chính xác!",
                    maxlength: "Tên đăng nhập tối đa 50 ký tự!"
                },
                DateOfBirth: {
                    required: "Xin hãy chọn ngày sinh!",
                    date: "Xin hãy nhập đúng định dạng!"
                },
                Gender: {
                    required: "Xin hãy chọn giới tính của bạn!"
                },
                Address: {
                    required: "Xin hãy chọn giới tính của bạn!",
                    maxlength: "Địa chỉ tối đa 250 ký tự!"
                },
                PhoneNumber: {
                    required: "Xin hãy nhập số điện thoại của bạn!"
                },
                Email: {
                    required: "Xin hãy nhập địa chỉ email của bạn!",
                    email: "Xin hãy nhập đúng định dạng email!",
                }
            },
            highlight: function (e) {
                $(e).closest('.control-group').removeClass('info').addClass('error');
            },
            success: function (e) {
                $(e).closest('.control-group').removeClass('error').addClass('info');
                $(e).remove();
            },
        });

        //Out focus FullName textbox, change class to infor (blue color)
        $("#fullNameGroup").focusout(function () {
            $("#fullNameGroup").addClass('info');
        });

        ////Out focus UserName, check duplicate UserName
        //$("#txtUserName").focusout(function () {
        //    if ($("#groupUserName").hasClass('error')) {
        //        $("#groupUserName").addClass('error');
        //    }
        //});
    });

    @*jQuery.validator.addMethod('dupUserNameCheck', function (UserName) {
        var postURL = "CheckDuplicateUserName";
        $.ajax({
            cache: false,
            async: false,
            type: "POST",
            data: "username=" + username,
            url: postURL,
            success: function (data) {
                if (data.isDuplicate) {
                    result = true;
                }
                else {
                    result = false;
                }
            }
        });
        return result;
    }, '');*@

    function onChangeTest(textbox) {
        newUserNameValue = textbox.value;
        oldUserNameValue = textbox.oldvalue;
        if (newUserNameValue != oldUserNameValue) {
            $.getJSON('@Url.Action("CheckDuplicateUserName", "User")', { username: $("#txtUserName").val() }, function (data) {
                if (data.isDuplicate) {
                    $("#groupUserName").addClass('error');
                    $("#duplicateUserName").show();
                } else {
                    $("#groupUserName").removeClass('error').addClass('info');
                    $("#duplicateUserName").hide();
                }
            });
        }
    }


</script>
